public class Solution852 {
    public int peakIndexInMountainArray(int[] arr) {
        int l=1,r=arr.length-2;
        while (l<=r){
            int mid=(l+r)/2;
            if (arr[mid]>arr[mid-1] && arr[mid]<arr[mid+1]){
                l=mid+1;
            }else if (arr[mid]<arr[mid-1] && arr[mid]>arr[mid+1]){
                r=mid-1;
            }else {
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution852().peakIndexInMountainArray(new int[]{0,2,1,0}));
    }
}
